/*
* All code licensed under the GPLv2 and CDDL.
* Please visit http://www.gnu.org/licenses/gpl-2.0.html
* and http://www.sun.com/cddl/cddl.html for the full versions of
* these licenses.
 */

package twitterapp;

/**
 *
 * @author Xolani
 */
public class Connection {

    public String Connection (String username, String password)
    {
        String output = "";
        //Make a class instance for the Twitter API.
        RestAPI API_Instance = new RestAPI();

        //Now open a connection...
        try
        {
            output = API_Instance.ConnectServer(username, password);
            API_Instance = null;
        }
        catch (Exception e)
        {
            javax.swing.JOptionPane.showMessageDialog(null, e +
                    "\n\nThere was a problem authenticating with the server." +
                    "\n\nThis is likely because the " +
                    "Server returned 401 response.");
            API_Instance = null;
        }
        finally
        {
            return output;
        }
    }

    /* Determines the type of API method the data has come from and invokes the
     * relevant classes/methods to handle the data.
    */
    public void HandleData (String data, String type)
    {
        xmlparsing parser = new xmlparsing();

        if (type.equalsIgnoreCase("account/verify_credentials") == true)
        {
            parser.VerifyCredentials(data);
        }
        else if (type.equalsIgnoreCase("account/rate_limit_status") == true)
        {

        }
        else if (type.equalsIgnoreCase("account/end_session") == true)
        {

        }
        else if (type.equalsIgnoreCase("account/update_delivery_device ") == true)
        {

        }
        else if (type.equalsIgnoreCase("account/update_profile_image ") == true)
        {

        }
        else if (type.equalsIgnoreCase("favorites") == true)
        {

        }
        else if (type.equalsIgnoreCase("favorites/create") == true)
        {

        }
        else if (type.equalsIgnoreCase("favorites/destroy") == true)
        {

        }
        else if (type.equalsIgnoreCase("statuses/public_timeline") == true)
        {

        }
        else if (type.equalsIgnoreCase("statuses/friends_timeline") == true)
        {

        }
        else if (type.equalsIgnoreCase("statuses/user_timeline") == true)
        {

        }
        else if (type.equalsIgnoreCase("statuses/mentions") == true)
        {

        }
        else
        {

        }
        parser = null;
    }
}
